from django.db import models

class Mapping(models.Model):
    mac = models.CharField(max_length=12, verbose_name="MAC码")
    sn = models.CharField(max_length=12, verbose_name="SN码")
    def __str__(self):
        return f"{self.mac} - {self.sn}"

    class Meta:
        verbose_name = "映射表"
        verbose_name_plural = verbose_name

class Settlement(models.Model):
    SOURCE_CHOICES = [
    (1, '购置'),
    (2, '赠送'),
    (3, '翻新'),
    (4, '其他'),
    ]

    STATUS_CHOICES = [
        (1, '待查'),
        (2, '疑似损失'),
        (3, '确认损失'),
        (4, '确认正常'),
    ]
    mac = models.CharField(max_length=12, verbose_name="MAC码")
    source = models.SmallIntegerField(choices=SOURCE_CHOICES, verbose_name="终端来源")
    type = models.CharField(max_length=30, verbose_name="终端类型")
    amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="结算金额")
    date0 = models.CharField(max_length=10, blank=True, verbose_name="购置日期")
    date1 = models.CharField(max_length=10, blank=True, verbose_name="翻新日期")
    fix = models.SmallIntegerField(default=0, verbose_name="翻新次数")
    times = models.SmallIntegerField(default=0, verbose_name="检查次数")
    mismapping = models.SmallIntegerField(default=0, verbose_name="映射错误") 
    blank = models.SmallIntegerField(default=0, verbose_name="未纳管次数")
    online = models.SmallIntegerField(default=0, verbose_name="在线次数")
    offline = models.SmallIntegerField(default=0, verbose_name="离线次数")
    manual = models.CharField(max_length=100, verbose_name="人工标注")
    status = models.SmallIntegerField(choices=STATUS_CHOICES, default=1, verbose_name='核查状态')
    category = models.CharField(max_length=30, blank=True, verbose_name="类别")

    def __str__(self):
        return f"{self.mac} - {self.type}"

    class Meta:
        verbose_name = "结算表"
        verbose_name_plural = verbose_name

class Category(models.Model):
    type = models.CharField(max_length=30, verbose_name="终端类型")
    category = models.CharField(max_length=30, verbose_name="类别")
    def __str__(self):
        return self.category
    class Meta:
        verbose_name = "类别"
        verbose_name_plural = verbose_name